package developerworks.jetty6;

//import java.sql.*;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConnection {
	public DBConnection() {}
	
	
	public static final String DATABASE_USER = "root";
	public static final String DATABASE_PASSWORD = "In4mation1";
    public static final String MYSQL_AUTO_RECONNECT = "true";
    public static final String MYSQL_MAX_RECONNECTS = "4";
	private static Connection con;
	
	public static Connection open() {
		String driver = "org.gjt.mm.mysql.Driver";
		try{
			Class.forName(driver);
		     String dbURL = "jdbc:mysql://localhost/jabbify_development";
	
	        java.util.Properties connProperties = new java.util.Properties();
	        connProperties.put("user", DATABASE_USER);
	        connProperties.put("password", DATABASE_PASSWORD);
	        connProperties.put("autoReconnect", MYSQL_AUTO_RECONNECT);
	        connProperties.put("maxReconnects", MYSQL_MAX_RECONNECTS);
	        return DriverManager.getConnection(dbURL, connProperties);
		}catch(Exception e){
			 System.out.println("error"+e.toString());
		}
		return null;
       
    }
	public static Connection get(){
		try{
			if(con != null && ! con.isClosed()){
				return con;
			}
		}catch(Exception e){
			System.out.println("error");
		}
		
		con = open();
		return con;
	}
	        

    
    
}
